gusucode.com > VC++ 宾馆管理系统(MSSQL) > VC++ 宾馆管理系统(MSSQL)/gusucode/Code/LoginDLG.cpp

    //Download by http://www.NewXing.com
// LoginDLG.cpp : implementation file
//

#include "stdafx.h"
#include "Hotel_MIS.h"
#include "LoginDLG.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoginDLG dialog

CLoginDLG::CLoginDLG(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDLG::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDLG)
	m_sPWD = _T("");
	m_sUSER = _T("Administrator");
	//}}AFX_DATA_INIT
}


void CLoginDLG::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDLG)
	DDX_Text(pDX, IDC_LOGIN_PWD, m_sPWD);
	DDX_Text(pDX, IDC_LOGIN_USER, m_sUSER);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDLG, CDialog)
	//{{AFX_MSG_MAP(CLoginDLG)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoginDLG message handlers

BOOL CLoginDLG::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	((CEdit*)GetDlgItem(IDC_LOGIN_USER))->SetLimitText(15);
    ((CEdit*)GetDlgItem(IDC_LOGIN_PWD))->SetLimitText(10);
	
	// Set Caption Font
	//CFont m_Font;
    m_fMyFont.CreatePointFont(180,"华文彩云",NULL);
        
	((CStatic *)GetDlgItem(IDC_LOGIN_CAPTION))->SetFont(&m_fMyFont, true);;
        	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLoginDLG::OnOK() 
{
	// TODO: Add extra validation here
	// Check UserName Vadilaty
	UpdateData(true);
	
	m_sUSER.TrimRight(" ");

	if ( ""==m_sUSER )
	{
		AfxMessageBox(_T("请填写用户名"), MB_ICONEXCLAMATION);
        return;
	}
		
	_variant_t Holder, strQuery;
    strQuery = "select user_ID, user_PWD from user_Info where user_ID='"+m_sUSER+"'";
	theApp.ADOExecute(theApp.m_pADOSet, strQuery);
	int iCount = theApp.m_pADOSet->GetRecordCount();
	if ( 0==iCount ) 
	{
		theApp.m_iLoginCount++;
		if ( theApp.m_iLoginCount>2 ) 
		{
			AfxMessageBox("没有这个用户\n三次输入均不正确,请核对后再来", MB_ICONEXCLAMATION);	
			CDialog::OnCancel();
		    return;
		}
		AfxMessageBox("没有这个用户,请重新输入用户名", MB_ICONEXCLAMATION);	
	    return;
	}
	
	CString sPWD;
	theApp.m_pADOSet->MoveFirst();
	Holder = theApp.m_pADOSet->GetCollect("user_PWD");
	sPWD = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
	if ( 0!=sPWD.Compare(m_sPWD) )
	{
		theApp.m_iLoginCount++;
		if ( theApp.m_iLoginCount>2 ) 
		{
			AfxMessageBox("输入密码不正确\n三次输入均不正确,请核对后再来", MB_ICONEXCLAMATION);	
			CDialog::OnCancel();
		    return;
		}
		AfxMessageBox("输入密码不正确,请重新输入", MB_ICONEXCLAMATION);	
	    return;
	}
	
	// Get Login User
	theApp.m_sCurrentUser = m_sUSER;
	
	CDialog::OnOK();
}